<% interfaces_invalid = @host.interfaces.any?{ |i| i.errors.present? } %>

<fieldset id="interfaces" data-url="<%= new_interface_path %>">
  <% if interfaces_invalid %>
    <%= alert :class => 'alert-danger', :header => '', :text => _("Some of the interfaces are invalid. Please check the table below.") %>
  <% end %>
  <!-- interface list -->
  <table class="<%= table_css_classes %>" id="interfaceList">
    <thead>
      <tr>
        <th class="hidden-xs" width="3%"></th>
        <th class="hidden-xs" width="6%"></th>
        <th class="ellipsis"><%= _('Identifier') %></th>
        <th class="hidden-xs"><%= _('Type') %></th>
        <th class="hidden-xs"><%= _("MAC Address") %></th>
        <th class="hidden-xs"><%= _("IPv4 Address") %></th>
        <th class="hidden-xs"><%= _("IPv6 Address") %></th>
        <th class="hidden-xs"><%= _("FQDN") %></th>
        <th><%= _('Actions') %></th>
      </tr>
    </thead>
    <tbody>
      <tr id="interfaceTemplate" style="display: none">
        <td class="status hidden-xs" align="center"></td>
        <td class="flags hidden-xs" align="center"></td>
        <td class="identifier ellipsis"></td>
        <td class="type hidden-xs"></td>
        <td class="mac hidden-xs"></td>
        <td class="ip hidden-xs"></td>
        <td class="ip6 hidden-xs"></td>
        <td class="fqdn hidden-xs"></td>
        <td>
          <button type="button" class="btn btn-default showModal"><%= _('Edit') %></button>
          <button type="button" class="btn btn-danger removeInterface"><%= _('Delete') %></button>
        </td>
      </tr>
    </tbody>
  </table>

  <div class="btn-toolbar">
    <button type="button" onclick="edit_interface();return false;"
      class="info btn btn-success" id="addInterface"
                                   title="add new network interface">+ <%= _('Add Interface') %>
    </button>
  </div>

  <!-- hidden interface forms -->
  <div id="interfaceForms">
    <%= f.fields_for :interfaces do |interface| %>
      <%= render :partial => interface.object, :locals => {:f => interface, :id => interface.object.object_id}, :layout => 'nic/hidden_layout' %>
    <% end %>
  </div>
  <!-- modal window -->
  <div class="modal fade" id="interfaceModal" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" onclick="close_interface_modal(); return false;"><span aria-hidden="true">&times;</span><span class="sr-only"><%= _('Close') %></span></button>
          <h4 class="modal-title"></h4>
        </div>
        <div class="modal-body">
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn btn-default" onclick="close_interface_modal(); return false;"><%= _('Cancel') %></button>
          <button type="button"  class="btn btn-primary" onclick="save_interface_modal(); return false;"><%= _('Ok') %></button>
        </div>
      </div>
    </div>
  </div>

  <%= new_child_fields_template(f, :interfaces, {:partial => Nic::Managed.new, :layout => 'nic/hidden_layout'}) %>

</fieldset>
